<?php 

/*====================================================
 Author: RooTM
------------------------------------------------------
 Web-site: http://weboss.net/
=====================================================*/

$color_groups = "group_1:#FF0000,group_2:#CC33CC,group_3:#009900,group_4:#3333FF";

@session_start();
@error_reporting ( E_ALL ^ E_WARNING ^ E_NOTICE );
@ini_set ( 'display_errors', true );
@ini_set ( 'html_errors', false );
@ini_set ( 'error_reporting', E_ALL ^ E_WARNING ^ E_NOTICE );

define( 'DATALIFEENGINE', true );
define( 'ROOT_DIR', substr( dirname(  __FILE__ ), 0, -26 ) );
define( 'ENGINE_DIR', ROOT_DIR . '/engine' );

include ENGINE_DIR . '/data/config.php';

if( $config['http_home_url'] == "" ) {
	
	$config['http_home_url'] = explode( "engine/iLike/ajax.php", $_SERVER['PHP_SELF'] );
	$config['http_home_url'] = reset( $config['http_home_url'] );
	$config['http_home_url'] = "http://" . $_SERVER['HTTP_HOST'] . $config['http_home_url'];

}

require_once ENGINE_DIR . '/classes/mysql.php';
require_once ENGINE_DIR . '/data/dbconfig.php';
require_once ENGINE_DIR . '/modules/functions.php';

$_COOKIE['dle_skin'] = trim(totranslit( $_COOKIE['dle_skin'], false, false ));

if( $_COOKIE['dle_skin'] ) {
	if( @is_dir( ROOT_DIR . '/templates/' . $_COOKIE['dle_skin'] ) ) {
		$config['skin'] = $_COOKIE['dle_skin'];
	}
}

if( $config["lang_" . $config['skin']] ) {
	if ( file_exists( ROOT_DIR . '/language/' . $config["lang_" . $config['skin']] . '/website.lng' ) ) {	
		include_once ROOT_DIR . '/language/' . $config["lang_" . $config['skin']] . '/website.lng';
	} else die("Language file not found");
} else {
	
	include_once ROOT_DIR . '/language/' . $config['langs'] . '/website.lng';

}

$config['charset'] = ($lang['charset'] != '') ? $lang['charset'] : $config['charset'];

require_once ENGINE_DIR . '/modules/sitelogin.php';

if( ! $is_logged ) die( "error" );

$news_id = trim($_POST['news_id']);

$comment_id = trim($_POST['comment_id']);

$action_hash = trim($_POST['action_hash']);

if($_POST['place'] != 'news') $_POST['place'] = 'comments';

$place = $_POST['place'];

if( !is_numeric($news_id) OR $action_hash != md5( md5($_POST['place']) . md5($news_id) . md5($comment_id) . md5(DBPASS) . md5($member_id['name']) ) ) die( "error" );

if($place != 'news')if( !is_numeric($comment_id) ) die( "error" );

$color = stristr($color_groups, 'group_'.$member_id['user_group'].':' );
$color = reset(explode(',',$color));
$color = trim(str_replace('group_'.$member_id['user_group'].':','',$color));

if( $config['allow_alt_url'] == "yes" ) $go_page = $config['http_home_url'] . "user/" . urlencode( $member_id['name'] ) . "/";
	 else $go_page = "$PHP_SELF?subaction=userinfo&amp;user=" . urlencode( $member_id['name'] );
			
$user = "<a onclick=\"ShowProfile('" . urlencode( $member_id['name'] ) . "', '" . $go_page . "'); return false;\" href=\"" . $go_page . "\"><b><span style=\"color:".$color."\">" . $member_id['name'] . "</span></b></a>";

if($place == 'news') $file_name = ENGINE_DIR . '/modules/iLike/base/news-'.$news_id.'.data';
if($place == 'comments') $file_name = ENGINE_DIR . '/modules/iLike/base/nid-'.$news_id.'_cid-'.$comment_id.'.data';

$like_data = @file_get_contents( $file_name );

if($_POST['action'] == 'plus' AND !preg_match( "<!-- UserID: ".$member_id['user_id']." -->" , $like_data ) ){

$like_file = fopen($file_name , 'w+');
fwrite($like_file, "<!-- UserID: ".$member_id['user_id']." -->".$user."\n\n".$like_data);
fclose($like_file);

}elseif($_POST['action'] == 'minus' AND preg_match( "<!-- UserID: ".$member_id['user_id']." -->" , $like_data ) ){

$like_file = fopen( $file_name , 'w+');
fwrite($like_file, str_replace ( "<!-- UserID: ".$member_id['user_id']." -->".$user."\n\n" , '' ,  $like_data ) );
fclose($like_file);

}

$run_in = 'AJAX';

@header( "Content-type: text/html; charset=" . $config['charset'] );

include ENGINE_DIR . '/modules/iLike/show.php';

?>